<template>
	<view>
		<view class="tui-actionsheet-class tui-actionsheet" :class="(show ? 'tui-actionsheet-show' : '')">
			<view class="top-box">
				<view class="information">
					<view class="left">
						<image class="images" :src="itemList.avatar" mode="aspectFill"></image>
					</view>
					<view class="right">
						<view class="item-row">
							<text>医师：</text>
							<text class="small-size">{{ itemList.name }}</text>
						</view>
						<!-- <view class="item-row">
							<text>门店：</text>
							<text>{{ itemList.mer_name }}</text>
						</view> -->
						<view class="item-row">
							<text>费用：</text>
							<text class="money small-size">{{ itemList.money }}</text>
						</view>
						<view class="item-row">
							<text>时段：</text>
							<view class="telts small-size">
								<text>{{ itemList.create_time }}{{ itemList.dates }}</text>
								<text v-for="(item, index) in itemList.tiem">-{{ item }}</text>
							</view>
						</view>
					</view>
				</view>
				<text class="Tips">请点击下方加号添加身份</text>
				<view class="the_patient">
					<view class="circle" v-if="testdatalist.name != ''" @click="addthepatient">{{ testdatalist.name }}
					</view>
					<view v-if="testdatalist.name == ''" class="addtocircle" @click="addthepatient">+</view>
				</view>
				<view class="notice">预约服务须知:</view>
				<view class="notice_article">
					<view>1、您可以在我的预约单查看订单详情。</view>
					<view>2、如果您预约成功,由于个人原因不能及时到店,请及时取消订单。</view>
					<view>3、详细的服务流程以店内为准</view>
				</view>
			</view>
			<!-- hover-class="tui-actionsheet-hover" -->

			<!-- <view :show="true">
				<view class="tishi">
					请添加预约人
				</view>
			</view> -->
			<view style="color: #ffffff;" class="tui-actionsheet-btn tui-actionsheet-cancel" :hover-stay-time="150"
				@tap="handleClickCancel(itemList.id, itemList.money)">确认预约</view>
		</view>
		<view class="tui-actionsheet-mask" :class="(show ? 'tui-mask-show' : '')" @tap="handleClickMask"></view>

		<payment :payMode="payMode" :pay_close="pay_close" @onChangeFun="onChangeFun" :order_id="pay_order_id"
			:totalPrice="totalPrice" :order_type="3"></payment>
	</view>
</template>

<script>
	let app = getApp();
	import payment from "@/components/payment";
	import {
		getUserInfo
	} from "@/api/user";
	import {
		postConfirm
	} from "@/api/appointment.js";
	export default {
		name: "makeAppointment",
		props: {
			//点击遮罩 是否可关闭
			maskClosable: {
				type: Boolean,
				default: true
			},
			//显示操作菜单
			show: {
				type: Boolean,
				default: false
			},
			itemList: {},
			testdatalist: {},
			//提示文字
			tips: {
				type: String,
				default: ""
			},
			//提示文字颜色
			color: {
				type: String,
				default: "#9a9a9a"
			},
			//提示文字大小 rpx
			size: {
				type: Number,
				default: 26
			},
			//是否需要取消按钮
			isCancel: {
				type: Boolean,
				default: true
			},
			appData: {
				type: Object,
				default: function() {
					return {};
				}
			}
		},
		components: {
			payment
		},
		data() {
			return {
				formAppointment: {
					doctor_id: "",
					patient_ids: "", //就诊人id
					service_time: {
						region: "",
						time: []
					} //服务时间
				},
				key: "",
				pay_close: false,
				pay_order_id: "",
				totalPrice: "0",

				payMode: [{
						name: "微信支付",
						icon: "icon-weixinzhifu",
						value: "wechat",
						title: "微信快捷支付",
						payStatus: 1
					},
					{
						name: "支付宝支付",
						icon: "icon-zhifubao",
						value: "alipay",
						title: "支付宝支付",
						payStatus: app.globalData.alipay_open
					},
					{
						name: "余额支付",
						icon: "icon-yuezhifu",
						value: "balance",
						title: "可用余额:",
						number: 0,
						payStatus: app.globalData.yue_pay_status
					}
				],
				userInfo: {},
			};
		},
		created() {
			this.getUserInfo();
			this.payMode[1].payStatus = this.appData ? this.appData.alipay_open : 1;
			this.payMode[2].payStatus = this.appData ? this.appData.yue_pay_status : 1;
		},
		methods: {
			/**
			 * 获取用户信息
			 *
			 */
			getUserInfo: function() {
				let that = this;
				getUserInfo()
					.then(res => {
						that.userInfo = res.data;
						that.payMode[2].number = res.data.now_money;
						// that.$set(that, 'payMode', that.payMode);
					})
					.catch(err => {
						return this.$util.Tips({
							title: err
						});
					});
			},
			handleClickMask() {
				if (!this.maskClosable) return;
				this.$emit("chooseCancel");
			},
			handleClickItem(e) {
				if (!this.show) return;
				const dataset = e.currentTarget.dataset;
				this.$emit("click", {
					index: dataset.index
				});
			},
			handleClickCancel(order_id, pay_price) {
				this.formAppointment.doctor_id = this.itemList.id;
				this.formAppointment.patient_ids = this.testdatalist.id;
				// var data = this.itemList.tiem[0] + "-" + this.itemList.tiem[1]
				// this.formAppointment.service_time = data
				this.formAppointment.service_time.region = this.itemList.dates;
				this.formAppointment.service_time.time = this.itemList.tiem;
				this.formAppointment.service_time.day = this.itemList.day;
				if (this.testdatalist.name == "") {
					return this.$util.Tips({
						title: "请添加身份信息"
					});
				}
				if (this.userInfo.is_inquiry == 1) {
					return this.$util.Tips({
						title: this.userInfo.is_inquiry_msg
					});
				}

				console.log('rk===>[p]' + JSON.stringify(this.formAppointment));
				postConfirm(this.formAppointment)
					.then(res => {
						// this.key = res.data.doctor_order_key
						this.$emit("chooseCancel");
						this.$set(this, "pay_close", true);
						// this.order_id = res.data.doctor_order_key;
						this.pay_order_id = res.data.doctor_order_key;
						// this.$set(this, 'pay_order_id', );
						this.$set(this, "totalPrice", pay_price);
					})
					.catch(err => {
						return this.$util.Tips({
							title: err
						});
					});
			},
			addthepatient() {
				uni.navigateTo({
					url: "/pages/shops/subs_appointment/thepatient/index"
				});
			},
			/**
			 * 关闭支付组件
			 *
			 */
			payClose: function() {
				this.pay_close = false;
				this.$emit("payClose");
			},
			/**
			 * 支付成功回调
			 *
			 */
			pay_complete: function() {
				this.loadend = false;
				this.page = 1;
				this.$set(this, "orderList", []);
				this.pay_close = false;
				this.pay_order_id = "";
				// this.getOrderData();
				// this.getOrderList();
			},
			/**
			 * 支付失败回调
			 *
			 */
			pay_fail: function() {
				this.pay_close = false;
				this.pay_order_id = "";
			},
			/**
			 * 事件回调
			 *
			 */
			onChangeFun: function(e) {

				console.log('rk==>' + JSON.stringify(e));

				let opt = e;
				let action = opt.action || null;
				let value = opt.value != undefined ? opt.value : null;
				action && this[action] && this[action](value);
			}
		}
	};
</script>

<style lang="scss">
	.tishi {
		border: 2upx solid #9c9c9c;
		position: fixed;
		top: 30%;
		left: 50%;
		transform: translate(-50%, -50%);
		z-index: 999;
		width: 360upx;
		height: 100upx;
		background-color: #ffffff;
	}

	.top-box {
		background-color: #ff0000;
		height: 680upx;
		padding: 20upx;
		background-color: #ffffff;

		.information {
			padding-bottom: 10upx;
			border-bottom: 2upx solid #cecece;
			display: flex;

			.left {
				width: 180upx;
				height: 180upx;
				margin-right: 30upx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.right {
				display: flex;
				flex-direction: column;
				justify-content: space-around;

				.item-row {
					display: flex;
					align-items: center;
				}
				.small-size {
					font-size: 24rpx;
				}
				.telts {
					// margin-top: 6upx;
					// font-size: 24upx;
					display: flex;
					align-items: center;
				}

				view {
					font-size: 28upx;
					font-family: Source Han Sans CN;
					font-weight: 600;
					color: #3e3e3e;
					display: flex;
					// margin-bottom: 26upx;

					.money {
						color: #e93429;
					}
				}
			}
		}

		.the_patient {
			display: flex;
			margin-top: 40upx;
			margin-bottom: 40upx;

			.circle {
				width: 120upx;
				height: 120upx;
				margin-right: 20upx;
				background-color: #fee3d9;
				color: #e35812;
				font-size: 70upx;
				text-align: center;
				line-height: 110upx;
				border-radius: 50%;
			}

			.addtocircle {
				width: 120upx;
				height: 120upx;
				margin-right: 10upx;
				border: 3upx solid #e93429;
				color: #e35812;
				font-size: 120upx;
				text-align: center;
				line-height: 100upx;
				border-radius: 50%;
			}
		}

		.notice {
			font-size: 26upx;
			font-family: Source Han Sans CN;
			font-weight: 600;
			color: #e93429;
		}

		.notice_article {
			font-size: 22upx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #3e3e3e;

			view {
				margin-bottom: 10upx;
			}
		}

		.Tips {
			font-size: 28upx;
			font-family: Source Han Sans CN;
			font-weight: 600;
			color: #3e3e3e;
		}
	}

	.tui-actionsheet {
		width: 100%;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 222;
		visibility: hidden;
		transform: translate3d(0, 100%, 0);
		transform-origin: center;
		transition: all 0.3s ease-in-out;
		background: #eaeaec;
		min-height: 100rpx;
	}

	.tui-actionsheet-show {
		transform: translate3d(0, 0, 0);
		visibility: visible;
	}

	.tui-operate-box {
		padding-bottom: 12rpx;
	}

	.tui-actionsheet-btn {
		background-color: $yy-main-col;
		color: #ffffff;
		width: 100%;
		height: 100rpx;

		display: flex;
		align-items: center;
		justify-content: center;
		text-align: center;
		font-size: 36rpx;
		position: relative;
	}

	.tui-btn-last {
		padding-bottom: env(safe-area-inset-bottom);
	}

	.tui-actionsheet-divider::before {
		content: "";
		width: 100%;
		border-top: 1rpx solid #d9d9d9;
		position: absolute;
		top: 0;
		left: 0;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
	}

	.tui-actionsheet-cancel {
		color: #1a1a1a;
		// padding-bottom: env(safe-area-inset-bottom);
	}

	.tui-actionsheet-hover {
		background: #f7f7f9;
	}

	.tui-actionsheet-mask {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: rgba(0, 0, 0, 0.6);
		z-index: 99;
		transition: all 0.3s ease-in-out;
		opacity: 0;
		visibility: hidden;
	}

	.tui-mask-show {
		opacity: 1;
		visibility: visible;
	}
</style>
